<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <link href="<?php echo base_url(); ?>css/bootstrap.min.css" rel="stylesheet" media="screen"/>
    <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery-1.8.3.min.js"></script>
    <title></title>
    <style type="text/css">
        .no{
            width: 19px;
            height: 20px;
            background-image: url(<?php echo base_url('img/y.png'); ?>);
            background-position: 19px 0px;
        }
        .yes{
            width: 20px;
            height: 20px;
            background-image: url(<?php echo base_url('img/y.png'); ?>);
            background-position: 0px 0px;
        }
        input, .no, .yes{
            display: inline-block;
        }
        
        body{
            overflow: hidden;
        }
    </style>
</head>
<body>
    <?php echo form_open('admin/update'); ?>
        <fieldset>
            <legend>Input <?php echo $row->level; ?></legend>
            <label for="nama">Nama</label>
            <input type="text" name="nama" id="nama" value="<?php echo $row->nama; ?>"/>
            <div class="yes nama"></div><div class="no nama"></div>
            <label for="username">Username</label>
            <input type="text" name="username" id="username" value="<?php echo $row->username; ?>"/>
            <div class="yes username"></div><div class="no username"></div>
            <label class="checkbox">
                <input type="checkbox" id="passcek" name="passcek" onclick="editpass()"/> Edit Password
            </label>
            <label for="password">New Password</label>
            <input type="text" name="password" onkeyup="cekpass()" onchange="cekpass()" id="password" disabled/>
            <input type="hidden" name="level" value="<?php echo $row->level; ?>"/>
            <input type="hidden" name="id_user" value="<?php echo $row->id_user; ?>"/>
            <input type="submit" value="Submit" id="submit" class="btn btn-primary pull-right" style="margin-right: 20px;"/>
        </fieldset>
    <?php echo form_close(); ?>
    <script type="text/javascript">
        $(document).ready(function(){
            $('.nama').hide();
            $('.username').hide();
//            $('#submit').addClass("disabled");
            
            $('#nama').blur(function(){
                if($(this).val() == ""){
                    $('.nama').fadeOut("slow");
                }else{
                    $.post("<?php echo site_url('admin/cek_nama'); ?>", { q:$(this).val() }, function(data){
                        if(data == 0){
                            $('.nama.no').hide();
                            $('.nama.yes').fadeIn("slow");
                            disn = 1;
                        }else{
                            $('.nama.yes').hide();
                            $('.nama.no').fadeIn("slow");
                            disn = 0;
                        }
                    });
                }
//                $('#submit').addClass("disabled");
            });
            
            $('#username').blur(function(){
                if($(this).val() == ""){
                    $('.username').fadeOut("slow");
                }else{
                    $.post("<?php echo site_url('admin/cek_username'); ?>", { q:$(this).val() }, function(data){
                        if(data == 0){
                            $('.username.no').hide();
                            $('.username.yes').fadeIn("slow");
                            disu = 1;
                        }else{
                            $('.username.yes').hide();
                            $('.username.no').fadeIn("slow");
                            disu = 0;
                        }
                    });
                }
//                $('#submit').addClass("disabled");
            });
        });
        
        function cekpass(){
            pas = $('#password').val();
            if(disu == 1 && disn == 1){
                $('#submit').removeClass("disabled");
            }else{
                $('#submit').addClass("disabled");
            }
        }
        
        function editpass(){
            if(document.getElementById("passcek").checked){
                $('#password').removeAttr("disabled");
            }else{
                document.getElementById("password").setAttribute("disabled", "disabled");
            }
        }
    </script>
</body>
</html>